package com.hnevc.recyclerviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    RecyclerView mRecyclerView ;
    List<Fruit> mFruitList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();

        mRecyclerView = (RecyclerView) findViewById(R.id.recyler_view);
        FruitAdapter adapter = new FruitAdapter(mFruitList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(adapter);

    }

    private void initData() {
        mFruitList = new ArrayList<Fruit>();
        String[] fruit_names = getResources().getStringArray(R.array.fruits);
        for (String name :
                fruit_names) {
            Fruit fruit = new Fruit();
            fruit.setName(name);
            fruit.setImageId(R.drawable.apple);
            mFruitList.add(fruit);
        }
    }
}
